package hk.polyu.dds;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.NetworkInfo;
import android.net.wifi.p2p.*;
import android.net.wifi.p2p.WifiP2pManager;
import android.net.wifi.p2p.WifiP2pManager.Channel;
import android.net.wifi.p2p.WifiP2pManager.PeerListListener;
import android.util.Log;

public class WiFiDirectBroadcastReceiver extends BroadcastReceiver {
	
    private WifiP2pManager 	mWifiP2pManager;
    private Channel 		mChannel;
    private MainUI			mMainUI;

    public WiFiDirectBroadcastReceiver(WifiP2pManager manager, Channel channel, MainUI main) {
        super();
        this.mWifiP2pManager = manager;
        this.mChannel = channel;
        this.mMainUI = main;
    }
	

	@Override
	public void onReceive(Context arg0, Intent intent) {
		/*
		String action = intent.getAction();
        if (WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION.equals(action)) {
            Log.d("polyu", "P2P state changed");
        } else if (WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION.equals(action)) {
            // This is an asynchronous call and the calling activity is notified with a
            // callback on PeerListListener.onPeersAvailable()
        	mWifiP2pManager.requestPeers(mChannel, mMainUI);
            Log.d("polyu", "P2P peers changed");
        } else if (WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION.equals(action)) {

            if (mWifiP2pManager == null)
                return;

            NetworkInfo networkInfo = (NetworkInfo) intent.getParcelableExtra(WifiP2pManager.EXTRA_NETWORK_INFO);

            if (networkInfo.isConnected()) {

                // we are connected with the other device, request connection
                // info to find group owner IP
            	mWifiP2pManager.requestConnectionInfo(mChannel, mMainUI);
            } else {
                // It's a disconnect
            	Log.d("polyu", "Peer disconnected");
            }
        } else if (WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION.equals(action)) {
        	Log.d("polyu", "WIFI_P2P_THIS_DEVICE_CHANGED_ACTION");

        }
        */
	}

}
